// 放不同 action 的地方
//actionCreators.js

import * as actionTypes from './constants';
import { fromJS } from "immutable";
import { getBannerApi, getRecommendListApi } from "../../../api/request";

// reduxAction
export const changeBannerList = ((data) => {
    return {
        type: actionTypes.CHANGE_BANNER,
        data: fromJS(data)
    };
});
// reduxAction
export const changeRecommendList = ((data) => {
    return {
        type: actionTypes.CHANGE_RECOMMEND_LIST,
        data: fromJS(data)
    }
});
// 页面操作
export const getBannerList = () => {
    return (dispatch) => {
        getBannerApi().then (data => {
            dispatch(changeBannerList (data.banners));
            dispatch (changeEnterLoading (false));// 改变 loading
        }).catch (() => {
            console.log ("轮播图数据传输错误");
        })
    }
};
// 页面操作
export const getRecommendList = () => {
    return (dispatch) => {
        getRecommendListApi().then (data => {
            dispatch (changeRecommendList (data.result));
        }).catch (() => {
            console.log ("推荐歌单数据传输错误");
        });
    }
};
// 加载组件
export const changeEnterLoading = (data) => ({
    type: actionTypes.CHANGE_ENTER_LOADING,
    data
});
